package com.partner.service;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.springframework.web.bind.annotation.ResponseBody;

import com.partner.dao.UserDao;
import com.partner.domain.Friend;
import com.partner.domain.MyFriend;
import com.partner.domain.MyTask;
import com.partner.domain.User;
import com.partner.domain.UserAndGroup;
import com.partner.domain.Yaoqingfriend;
import com.partner.response.LoginResponse;

/**
 * 有关用户的服务
 * @author Jinshuan
 *
 */
public class UserService {
	private UserDao userdao;
	public UserService(){
		userdao = new UserDao();
	}
	
	
	//新增用户
		public int insertUser(User user){
			return userdao.insertUser(user);
		}
		
		//登录servie
		public LoginResponse login(String phone,String password){
			return userdao.login(phone, password);
		}
		//修改用户信息
		public boolean updateUser(User user){
			return userdao.updateUser(user);
		}
		//得到对应用户的联系人列表
		public List<MyFriend> getMyFriends(String uid){
			return userdao.getMyFriends(uid);
		}
		//查询所有非好友
		public List<Friend> getNotFriend(String phone,String condition){
			//将user转为friend
			List<Friend> friends = new ArrayList<Friend>();
			List<User> users = userdao.getNotFriend(phone, condition);
			System.out.println(users);
			if(users!=null){
				for(User user:users){
					Friend friend = new Friend();
					friend.setPhoto(user.getPhoto());
					friend.setSchool(user.getSchool());
					friend.setUserId(user.getPhone());
					friend.setUserName(user.getUsername());
					friend.setYear(user.getYear());
					friend.setZhuanye(user.getZhuanye());
					friends.add(friend);
				}
				System.out.println(friends);
				return friends;
			}else{
				return null;
			}
		}
		
		//搜索对应的群
		public List<UserAndGroup> getNotGroups(String phone,String condition){
			return userdao.getNotGroups(phone, condition);
		}
		//单方面添加好友
		public boolean addFriend(String from,String to,String groupname,String nickname){
			return userdao.addFriend(from, to, groupname, nickname);
		}
		
		//是否有好友加我
		public List<User> getFriendNotice(String phone){
			return userdao.getFriendNotice(phone);
		}
		//同意好友加我
		public boolean agreeFriend(String from,String to,String nickname,String groupname){
			return userdao.agreeFriend(from, to, nickname, groupname);
		}
		
		//如果明确是拒绝
		public boolean declineAddFriend(String from,String to){
			return userdao.declineAddFriend(from, to);
		}
		//加入群
		public boolean joinGroup(String userId,String groupId,String groupName,String nickName){
			return userdao.joinGroup(userId, groupId, groupName, nickName);
		}
		
		//是否有群加我
		public List<Yaoqingfriend> getGroupNotice(String phone){
			return userdao.getGroupNotice(phone);
		}
		
		//去查询我的任务
		public List<MyTask> selectMyTask(String phone,int pageNow,int pageSize){
			return userdao.selectMyTask(phone,pageNow,pageSize);
		}
		
		//删除其中一个任务
		public boolean deleteMyTask(String phone,String create_time){
			return userdao.deleteMyTask(phone, create_time);
		}
		//增加我的任务
		public boolean addTask(String task,String start_time ,String end_time,String questcode,String create_time,String phone){
			return userdao.addTask(task, start_time, end_time, questcode, create_time, phone);
		}
		//更改任务的状态
		public boolean updateTask(String state ,String phone,String create_time){
			return userdao.updateTask(state, phone, create_time);
		}
		//邀请好友加入对应的群。这时要得到不是这个群的好友
		public List<MyFriend> getMyFriendsNotInGroup(String uid,String groupId){
			return userdao.getMyFriendsNotInGroup(uid, groupId);
		}
		//修改密码
		public int updatePassword(String phone,String oldPassword,String newPassword){
			return userdao.updatePassword(phone, oldPassword, newPassword);
		}
		//将绑定的手机号给找回来
		public String findBindPhone(String phone){
			return userdao.findBindPhone(phone);
		}
		//忘记密码的时候修改密码
		public  boolean updatePwd(String phone,String newPassword){
			return userdao.updatePwd(phone, newPassword);
		}
		//修改用户头像
		public boolean updateUserImgIcon(String phone,String img){
			return userdao.updateUserImgIcon(phone,img);
		}
}
